home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / irit / windows.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  6.2 KB  |  218 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d (not only polygonal) solid modeller.             *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. * Module to handle the windows used by the solid modeller.             *
  7. *****************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include "program.h"
  13. #include "irit_soc.h"
  14. #include "iritprsr.h"
  15. #include "windows.h"
  16.  
  17. #define IRIT_PROMPT    "Irit> "
  18.  
  19. /*****************************************************************************
  20. *  Routine to toggle the input window log file printing. If turned on, test  *
  21. * is made if file has been opened and if not open it.                 *
  22. *****************************************************************************/
  23. void WndwLogPrint(RealType *Set)
  24. {
  25.     char s[LINE_LEN];
  26.  
  27.     if (APX_EQ(*Set, 0.0)) {
  28.     GlblPrintLogFile = FALSE;
  29.     fflush(GlblLogFile);
  30.     return;
  31.     }
  32.  
  33.     if (GlblLogFile == NULL) {              /* Not open yet - open it now: */
  34.     if ((GlblLogFile = fopen(GlblLogFileName, "w")) == NULL) {
  35.         sprintf(s, "Failed to open log file \"%s\"", GlblLogFileName);
  36.         WndwInputWindowPutStr(s);
  37.         return;
  38.     }
  39.     GlblPrintLogFile = TRUE;
  40.     }
  41. }
  42.  
  43. /*****************************************************************************
  44. *  Routine to wait for user keystroke while drawing blinking cursor:         *
  45. * No data is returned - used as pause only.                     *
  46. *****************************************************************************/
  47. void WndwPause(RealType *R)
  48. {
  49. #ifdef DJGCC
  50.     if (!APX_EQ(*R, 0.0))
  51.     while (kbhit())
  52.         getkey();                         /* Flush stdin. */
  53.     WndwInputWindowPutStr("Type return to continue:");
  54.     getkey();
  55. #else
  56.     fprintf(stderr, "Type return to continue:");
  57.     fflush(stderr);
  58.  
  59.     getchar();
  60. #endif /* DJGCC */
  61. }
  62.  
  63. /*****************************************************************************
  64. *  Routine to handle the text on the Input Window. This window echoes all    *
  65. * the input steam - the input parser input. Errors or information is also    *
  66. * displayed in this window.                             *
  67. *****************************************************************************/
  68. void WndwInputWindowPutStr(char *Msg)
  69. {
  70.     char str[INPUT_LINE_LEN];
  71.     int i;
  72.  
  73.     for (i = 0; *Msg != 0; Msg++) {
  74.     if (*Msg == 0x09)
  75.         do {
  76.         str[i++] = ' ';
  77.         }
  78.         while (i % 8 != 0);
  79. #ifdef AMIGA
  80.     else if (abs(*Msg) < ' ' || (abs(*Msg) > '~' && abs(*Msg) <0xA0))
  81. #else
  82.     else if (*Msg < ' ' || *Msg > '~')
  83. #endif
  84.         break;
  85.     else
  86.         str[i++] = *Msg;
  87.     }
  88.     str[i] = 0;
  89.  
  90.     if (GlblPrintLogFile)
  91.     fprintf(GlblLogFile, "%s\n", str);
  92.  
  93. #ifdef DJGCC
  94.     if (GlblDoGraphics) {
  95.     IntrPrintf(InputWindowID, TRUE, str);
  96.     }
  97.     else {
  98.     printf("%s\n", str);
  99.     fflush(stdout);
  100.     }
  101. #else
  102.     printf("%s\n", str);
  103.     fflush(stdout);
  104. #endif /* DJGCC */
  105. }
  106.  
  107. /*****************************************************************************
  108. *  Routine to handle reading one line from stdin into string Str, with max.  *
  109. * length Length in the Input Window.                         *
  110. *  Note Str may be non empty and can be used to fix wrong entry.         *
  111. *****************************************************************************/
  112. void WndwInputWindowGetStr(char *Str, int Length)
  113. {
  114. #ifdef DJGCC
  115.     if (GlblDoGraphics) {
  116.     Str[0] = 0;
  117.         IntrGetLineWindow(InputWindowID, Str, Length);
  118.     }
  119.     else {
  120.     printf(IRIT_PROMPT);
  121.     fgets(Str, Length - 1, stdin);
  122.     if (feof(stdin))
  123.         IritExit(0);       /* Eof typed on keyboard (usually CtrlD). */
  124.     if (Str[strlen(Str) - 1] < ' ')
  125.         Str[strlen(Str) - 1] = 0;                /* No CR/LF. */
  126.     puts(Str);
  127.     fflush(stdout);
  128.     } 
  129. #else
  130.     printf(IRIT_PROMPT);
  131.     fgets(Str, Length - 1, stdin);
  132.     if (feof(stdin))
  133.     IritExit(0);           /* Eof typed on keyboard (usually CtrlD). */
  134.     if (Str[strlen(Str) - 1] < ' ') 
  135.     Str[strlen(Str) - 1] = 0;                /* No CR/LF. */
  136.     puts(Str);
  137.     fflush(stdout);
  138. #endif /* DJGCC */
  139. }
  140.  
  141. /*****************************************************************************
  142. *  Display one object.                                 *
  143. *****************************************************************************/
  144. void WndwViewObject(IPObjectStruct *PObj)
  145. {
  146.     if (!GlblDoGraphics)
  147.     return;
  148.  
  149.     if (IP_IS_STR_OBJ(PObj)) {
  150.     if (!SocServerActive())
  151.         return;
  152.  
  153.     SocServerWriteOneObject(PObj);
  154.  
  155.     if (strcmp(PObj -> Name, "COMMAND_") == 0 &&
  156.         (strcmp(PObj -> U.Str, "EXIT") == 0 ||
  157.          strcmp(PObj -> U.Str, "DISCONNECT") == 0))
  158.         SocServerCloseSocket();
  159.     }
  160.     else
  161.     SocServerWriteOneObject(PObj);
  162. }
  163.  
  164. /*****************************************************************************
  165. *  Clear the display device.                             *
  166. *****************************************************************************/
  167. void WndwViewClearScreen(void)
  168. {
  169.     IPObjectStruct
  170.     *PObj = IPAllocObject("COMMAND_", IP_OBJ_STRING, NULL);
  171.  
  172.     strcpy(PObj -> U.Str, "CLEAR");
  173.     WndwViewObject(PObj);
  174.     IPFreeObject(PObj);
  175. }
  176.  
  177. /*****************************************************************************
  178. *  Clear the display device.                             *
  179. *****************************************************************************/
  180. void WndwViewSaveMatrix(char *FileName)
  181. {
  182.     IPObjectStruct
  183.     *PObj = IPAllocObject("COMMAND_", IP_OBJ_STRING, NULL);
  184.  
  185.     sprintf(PObj -> U.Str, "MSAVE %s", FileName);
  186.     WndwViewObject(PObj);
  187.     IPFreeObject(PObj);
  188. }
  189.  
  190. /*****************************************************************************
  191. *  Disconnect from the display device.                         *
  192. *****************************************************************************/
  193. void WndwViewDisconnect(void)
  194. {
  195.     IPObjectStruct
  196.     *PObj = IPAllocObject("COMMAND_", IP_OBJ_STRING, NULL);
  197.  
  198.     strcpy(PObj -> U.Str, "DISCONNECT");
  199.     WndwViewObject(PObj);
  200.     IPFreeObject(PObj);
  201. }
  202.  
  203. /*****************************************************************************
  204. *  Force the display device to quit.                         *
  205. *****************************************************************************/
  206. void WndwViewExit(void)
  207. {
  208.     IPObjectStruct
  209.     *PObj = IPAllocObject("COMMAND_", IP_OBJ_STRING, NULL);
  210.  
  211.     /* The second exit should fail on write closing the connection locally. */
  212.     strcpy(PObj -> U.Str, "EXIT");
  213.     WndwViewObject(PObj);
  214.  
  215.     IPFreeObject(PObj);
  216.  
  217. }
  218.